package com.cqrcb.cloud.service.activity;

import com.cqrcb.cloud.entity.activity.io.ActivityIO;
import com.cqrcb.cloud.entity.api.req.Q;
import com.cqrcb.cloud.entity.api.res.R;
import com.cqrcb.cloud.entity.quota.io.MultiQuotaCtrlMarketMainIO;
import com.cqrcb.cloud.service.ActivityPerformService;
import com.cqrcb.cloud.service.quota.MultiQuotaCtrlMarketMainService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
* ActivityImpl
*
* @author 系统
* @date 2021-06-04 02:07:58
*/
@Slf4j
@Service
public class ActivityPerformServiceImpl implements ActivityPerformService {

    @DubboReference(retries = -1,check = false)
    private ActivityService activityService;

    @DubboReference(retries = -1,check = false)
    private MultiQuotaCtrlMarketMainService multiQuotaCtrlMarketMainService;

    public ActivityPerformServiceImpl() {
    }

    @Override
    public R perform(Q<ActivityIO> activityIOQ) {
        log.info("进入了-->");
        //调用活动,查看活动
        activityService.queryActivityById("xx1");
        //扣减额度
        multiQuotaCtrlMarketMainService.deductionFinancialProductQuota(buildQuotaVO(activityIOQ));
        //推送给客户经理
        activityService.sendTicketToCustomerManager();
        return R.status(true);
    }

    /**
     * 创建vo
     *
     * @param activityIOQ 活动ioq
     * @return {@link Q< MultiQuotaCtrlMarketMainIO >}
     */
    private Q<MultiQuotaCtrlMarketMainIO> buildQuotaVO(Q<ActivityIO> activityIOQ) {
        Q<MultiQuotaCtrlMarketMainIO> q = new Q<>();
        q.setHeader(activityIOQ.getHeader());
        MultiQuotaCtrlMarketMainIO io = new MultiQuotaCtrlMarketMainIO();
        io.setType("1");
        io.setDataType("org");
        io.setOperationType("2");
        io.setDataId("1111");
        io.setUseQuota(BigDecimal.valueOf(1));
        q.setBody(io);
        return q;
    }
}
